export class LocalDataService {
private userData = new BehaviorSubject<User>({} as User);
currentData$ = this.userData.asObservable();
constructor() { }
updateUserData(data: User) {
this.userData.next(data);
}
}
ngOnInit(): void {
this.localDataService.currentData$.subscribe((data) => {
this.user = data;
});
if (this.user !== undefined && this.user !== null) {
this.userName = 'Terry';
this.articleListService.getArticleList(this.user.IdUser).subscribe((data: any[]) => {
this.articles = data;
}, (error: any) => {
console.error(error);
});
}
}
constructor(
private router:Router,
private activatedRoute:ActivatedRoute,
private localDataService:LocalDataService,
private articleListService:ArticleListService
)
{
this.activatedRoute.params.
subscribe(params => {
const articleId:number = params['articleId'];
if (articleId) {
this.articleId = articleId;
}
else {
this.articleId = 0;
}
});
}